import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import employeesRoute from '@/router/modules/employees'
import departmentsRoute from '@/router/modules/departments'
import settingsRoute from '@/router/modules/settings'
import salarysRoute from '@/router/modules/salarys'
import socialRoute from '@/router/modules/social'
import attendancesRoute from '@/router/modules/attendances'
import approvalsRoute from '@/router/modules/approvals'
import permissionsRoute from '@/router/modules/permissions'

// 动态路由表，项目中不同的用户可以访问不同的功能
export const asyncRoutes = [
  // 先空着这里，后面来补充功能
  // 组织架构
  departmentsRoute,
  // 员工管理
  employeesRoute,

  // 角色管理
  settingsRoute,
  // 工资
  salarysRoute,
  // 社保
  socialRoute,
  // 考勤
  attendancesRoute,
  // 审批
  approvalsRoute,
  // 权限管理
  permissionsRoute
]
// 静态路由列表 谁都可以看
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/import', // excel导入功能
    component: Layout,
    hidden: true, // 左侧不显示
    children: [{
      path: '',
      component: () => import('@/views/import/index')
    }]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // 上线的时候，改成history模式
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]
})

const router = createRouter()

// 重置路由: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
